{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "48576d7a",
   "metadata": {},
   "source": [
    "* week04\n",
    "记录人：曾烨"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2a7afb68",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "bc1e047e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "API_KEY = '76-_4m_gpMf7ZJT9IN--sRnBETvlIitx'\n",
    "API_S = 'A4vJxaa7sQoogmb7QZ_Ce-Rt7nY0gAn9'\n",
    "FaceSet_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "payload = {\n",
    "    \"api_key\":API_KEY,\n",
    "    \"api_secret\":API_S\n",
    "}\n",
    "r = requests.post(url = FaceSet_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d709dfb2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1509c65e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '648ce0daf9a99867d37721abd3f32064',\n",
       " 'time_used': 182,\n",
       " 'face_count': 0,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1648466410,56633f8a-58ae-462a-9c7c-e9b8031dc6a7',\n",
       " 'outer_id': '',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "03aa8bb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 人脸识别实践——宿舍智能识别门禁系统 （xxx栋）\n",
    "## 创建FaceSet\n",
    "## 查询FaceSet\n",
    "## 存入face_token数据\n",
    "## 获取FaceSet信息数据\n",
    "## 人脸搜索\n",
    "## 人脸对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "fd0e97ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建faceset\n",
    "## 描述\n",
    "##创建一个人脸的集合 FaceSet，用于存储人脸标识 face_token。一个 FaceSet 能够存储10000个 face_token。\n",
    "##试用API Key可以创建1000个FaceSet，正式API Key可以创建10000个FaceSet。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d53aed12",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "375017ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. url\n",
    "FaceSet_Create_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/create'\n",
    "\n",
    "# 2.api账号/通行证\n",
    "API_key = '76-_4m_gpMf7ZJT9IN--sRnBETvlIitx'\n",
    "API_secret = 'A4vJxaa7sQoogmb7QZ_Ce-Rt7nY0gAn9'\n",
    "\n",
    "# 3. 请求方法: post \n",
    "\n",
    "#4.准备payload（酬载）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "}\n",
    "\n",
    "#5.发起请求\n",
    "r = requests.post(url = FaceSet_Create_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2953b392",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method Response.json of <Response [200]>>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "29738c29",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查询faceset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "a7e7b8f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. url\n",
    "FaceSet_getfacesets_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets'\n",
    "\n",
    "# 2.api账号/通行证\n",
    "API_key = '76-_4m_gpMf7ZJT9IN--sRnBETvlIitx'\n",
    "API_secret = 'A4vJxaa7sQoogmb7QZ_Ce-Rt7nY0gAn9'\n",
    "\n",
    "# 3. 请求方法: post \n",
    "\n",
    "#4.准备payload（酬载）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "}\n",
    "\n",
    "#5.发起请求\n",
    "r = requests.post(url = FaceSet_getfacesets_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "439387b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 91,\n",
       " 'facesets': [{'faceset_token': '5d159ab4e0f43c43c69cc0584af44e64',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '648ce0daf9a99867d37721abd3f32064',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '98cfa41956ba2d87769dbf14e8614ea3',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''}],\n",
       " 'request_id': '1648468984,3a72980a-27aa-4389-b812-474d1b629141'}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "1cf5789f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 更新人脸库信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "e94e8215",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. url\n",
    "FaceSet_update_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/update'\n",
    "\n",
    "# 2.api账号/通行证\n",
    "API_key = '76-_4m_gpMf7ZJT9IN--sRnBETvlIitx'\n",
    "API_secret = 'A4vJxaa7sQoogmb7QZ_Ce-Rt7nY0gAn9'\n",
    "\n",
    "# 3. 请求方法: post \n",
    "\n",
    "#4.准备payload（酬载）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'faceset_token':'98cfa41956ba2d87769dbf14e8614ea3',\n",
    "    'display_name':'广州南方学院0栋学生宿舍楼',\n",
    "    'new_out-id':'NFUSDOO',\n",
    "    'user_data':'6层 ,满员，女生宿舍，460位同学'\n",
    "}\n",
    "\n",
    "#5.发起请求\n",
    "r = requests.post(url = FaceSet_update_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "03c0e608",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 78,\n",
       " 'error_message': 'BAD_ARGUMENTS: user_data',\n",
       " 'request_id': '1648470616,e614b0e5-c437-42ed-aced-efd753f8eae9'}"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "176fc92b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 检查数据集信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "59938990",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. url\n",
    "FaceSet_getdetail_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail'\n",
    "\n",
    "# 2.api账号/通行证\n",
    "API_key = '76-_4m_gpMf7ZJT9IN--sRnBETvlIitx'\n",
    "API_secret = 'A4vJxaa7sQoogmb7QZ_Ce-Rt7nY0gAn9'\n",
    "\n",
    "# 3. 请求方法: post \n",
    "\n",
    "#4.准备payload（酬载）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'outer_id':'NFUSDOO'\n",
    "}\n",
    "\n",
    "#5.发起请求\n",
    "r = requests.post(url = FaceSet_getdetail_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "20569650",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 74,\n",
       " 'error_message': 'INVALID_OUTER_ID',\n",
       " 'request_id': '1648470623,48edccc9-85d7-46df-b853-140acbc0424c'}"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "b71d3787",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 人脸检测，获取人脸token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "69f41165",
   "metadata": {},
   "outputs": [],
   "source": [
    "import detect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "323d1d62",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module detect:\n",
      "\n",
      "NAME\n",
      "    detect\n",
      "\n",
      "FUNCTIONS\n",
      "    face_detect(API_key, API_sercret, image_path)\n",
      "        该函数为调用face++ face_detect接口\n",
      "\n",
      "FILE\n",
      "    c:\\users\\user\\detect.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(detect)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a5f0e03",
   "metadata": {},
   "outputs": [],
   "source": [
    "detect.face_detect(API_key,API_sercret,'图片路径')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c8ca8cc7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 人脸存放"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15de7d01",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.导入需要的requests模块\n",
    "import requests\n",
    "\n",
    "# 1.url\n",
    "faceset_update_url=\"https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "#2.api账户、通行证\n",
    "API_key=\"76-_4m_gpMf7ZJT9IN--sRnBETvlIitx\"\n",
    "API_sercret=\"A4vJxaa7sQoogmb7QZ_Ce-Rt7nY0gAn9\"\n",
    "\n",
    "#3. 请求方法：post，\n",
    "# 4.准备payload（）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_sercret,\n",
    "    'outer_id':'nf'\n",
    "\n",
    "}\n",
    "\n",
    "# 5.发起请求\n",
    "# 6. requests\n",
    "r = requests.post(faceset_update_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "702c8ee9",
   "metadata": {},
   "outputs": [],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2152dc85",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c317d9c3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d6d3c5b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "002e2923",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28b32ed4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d6082fd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c54973c0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08ba7d29",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20916b34",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9dbe8119",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
